package com.xinlu.common.game.bo;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.xinlu.common.game.dao.ScSjglDao;
import com.xinlu.common.game.value.ScSjglVo;
import com.xinlu.common.game.value.WcSjglVo;
import com.xinlu.derek.common.BaseBo;
import com.xinlu.persistence.ScSjgl;
import com.xinlu.persistence.WcSjgl;
import com.xinlu.util.tool.DateUtil;

public class ScSjglBo extends BaseBo {
	
	/********	DAO 注入	Start	*********/
	private ScSjglDao scSjglDao;
	
	public void setScSjglDao(ScSjglDao scSjglDao) {
		this.scSjglDao = scSjglDao;
	}

	/********	DAO 注入	End	*********/

	public List getLottyList(String yymmdd, String yxms) {

		String hhmmss = DateUtil.getFormatDate(DateUtil.HH_MI_SS, new Date());
		
//		if (yymmdd == null || yymmdd == "") {
//
//			yymmdd = "2009/12/01";
//		}
//		Timestamp currentTime = DateUtil.getTimestamp(DateUtil.getDate(DateUtil.YYYY_MM_DD_HH_MI_SS, yymmdd + " " + hhmmss));
//
//		List<ScSjgl> reList = this.sjSjglDao.getLottyList(currentTime, yxms);
		List<ScSjglVo> tranList = null;
		// if (reList != null && reList.size() > 0) {

		tranList = new ArrayList<ScSjglVo>();

//			for (ScSjgl wcSjgl : reList) {
				
		ScSjglVo vo = null;
		
		ScSjgl po = this.scSjglDao.getNewQishuXinxi(DateUtil.getDate(DateUtil.YYYY_MM_DD_HH_MI_SS, yymmdd + " " + hhmmss), yxms);
		
		if(po != null){
			
			Date startdate = po.getCjkssj();
			
			Date enddate = DateUtil.dateAdd(DateUtil.DAY, po.getXxts(), startdate);
			Date now = null;
			int j = 30;
			
			for (int i = 0; i < j; i++) {
				
				now = DateUtil.dateAdd(DateUtil.DAY, i, new Date());
				
				while (now.after(startdate) && now.before(enddate)) {
					i++;
					j++;
					now = DateUtil.dateAdd(DateUtil.DAY, i, new Date());
				}
				
				long bet = 0;
				if (now.before(startdate)) {
					
					bet = DateUtil.dateDiff(DateUtil.DAY, DateUtil.getDate(DateUtil.YYYYMMDD, DateUtil.getFormatDate(DateUtil.YYYY, new Date()) + "0101"), now);
				}
				
				if (now.after(enddate)) {
					
					bet = DateUtil.dateDiff(DateUtil.DAY, DateUtil.getDate(DateUtil.YYYYMMDD, DateUtil.getFormatDate(DateUtil.YYYY, new Date()) + "0101"), now) - po.getXxts();
				}
				
				String suffix = "";
				bet++;
				if (bet > 0 && bet < 10) {
					
					suffix = "00" + bet;
				}else if(bet > 10 && bet < 100){
					
					suffix = "0" + bet;
				}else{
					
					suffix = "" + bet;
				}
				
				vo = new ScSjglVo();
				vo.setQh(DateUtil.getFormatDate(DateUtil.YYYY, now) + suffix);
				tranList.add(vo);
			}
		}

				
//			}
//
//		}
		return tranList;
	}

	public ScSjglVo getNewQishuAndJiezhishijian(String yymmdd, String yxms) {

		String hhmmss = DateUtil.getFormatDate(DateUtil.HH_MI_SS, new Date());

		if (yymmdd == null || yymmdd == "") {

			yymmdd = "2009/12/01";
		}

		ScSjgl po = this.scSjglDao.getNewQishuXinxi(DateUtil.getDate(DateUtil.YYYY_MM_DD_HH_MI_SS, yymmdd + " " + hhmmss), yxms);

		if (po != null) {

			ScSjglVo vo = new ScSjglVo();
			
			Date now = new Date();
			
			Date startdate = po.getCjkssj();
			
			Date enddate = DateUtil.dateAdd(DateUtil.DAY, po.getXxts(), startdate);
			
			if (now.after(startdate) && now.before(enddate)) {
				
				return null;
			}
			
			long bet = 0;
			if (now.before(startdate)) {
				
				bet = DateUtil.dateDiff(DateUtil.DAY, DateUtil.getDate(DateUtil.YYYYMMDD, DateUtil.getFormatDate(DateUtil.YYYY, new Date()) + "0101"), now);
			}
			
			if (now.after(enddate)) {
				
				bet = DateUtil.dateDiff(DateUtil.DAY, DateUtil.getDate(DateUtil.YYYYMMDD, DateUtil.getFormatDate(DateUtil.YYYY, new Date()) + "0101"), now) - po.getXxts();
			}
			
			String suffix = "";
			bet++;
			if (bet > 0 && bet < 10) {
				
				suffix = "00" + bet;
			}else if(bet > 10 && bet < 100){
				
				suffix = "0" + bet;
			}else{
				
				suffix = "" + bet;
			}
			vo.setQh(DateUtil.getFormatDate(DateUtil.YYYY, new Date()) + suffix);
			
			

			// 截止时间
			vo.setQsjzsj(DateUtil.getFormatDate(DateUtil.YYYYMMDD, new Date()) + " " + DateUtil.getFormatDate(DateUtil.HH_MI_SS, new Date(po.getQsjzsj().getTime())));
			vo.setDgjssj(DateUtil.getFormatDate(DateUtil.YYYY_MM_DD, DateUtil.getCurrentdate()) + " " + DateUtil.getFormatDate(DateUtil.HH_MI, new Date(po.getQsjzsj().getTime())));
			
			vo.setNowtime(DateUtil.getFormatDate(DateUtil.YYYYMMDDHHMISS, new Date()));
			return vo;
		} else {

			// vo.setQh(DateUtil.getFormatDate(DateUtil.YYYYMMDD,
			// DateUtil.getCurrentdate()) + "-" + po.getQh());

			// vo.setQs("暂不开奖..");
			// 截止时间
			// vo.setQsjzsj(DateUtil.getFormatDate(DateUtil.HH_MI_SS, new
			// Date(po.getQsjzsj().getTime())));
		}
		// 开奖时间
		// vo.setDgjssj(DateUtil.getFormatDate(DateUtil.YYYYMMDD,
		// DateUtil.getCurrentdate()) + " " +
		// DateUtil.getFormatDate(DateUtil.HH_MI_SS, new
		// Date(po.getQsjzsj().getTime())));

		return null;
	}
	
}
